package game;


import gui.Board;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ItemListener;
import java.util.LinkedList;
import java.util.Random;


/**
 * 
 * @author Vanessa Sousa
 *
 */

public class Snake implements Runnable {

	private LinkedList<Cell> cells = new LinkedList<Cell>();
	private Direction direction;
	private static final int SPEED = 5;
	private Thread thread;
	private Board board;
	private int bonusCount;
	private Random random;


	public Snake(Board board, LinkedList<Cell> cells, Direction direction, int bonus) {
		this.cells = cells;
		this.direction = direction;
		this.board = board;
		this.bonusCount = bonus;
		this.random = random;
	}

	public void start() {
		if (thread == null) {
			thread = new Thread(this);
			thread.start();
		}
	}

	public LinkedList<Cell> getCells() {
		return cells;
	}

	public void run() {
		move();

	}

	public void move() {
		Cell headOfSnake = cells.peekFirst();
		Cell newCell = board.requestCell(this, headOfSnake);
		Cell tailOfSnake = cells.peekLast();
		
		cells.remove(tailOfSnake);
		cells.push(newCell);
	}


	/**
	 * This method is responsible for drawing the snake.
	 * @param g
	 * @param cellWidth
	 * @param cellHeight
	 */

	public void draw(Graphics g, int cellWidth, int cellHeight) {
		System.out.println("Tamanho cells: " + cells.size());
		for (Cell cell : cells) {
			cell.draw(g, cellWidth, cellHeight, Color.CYAN, Color.BLACK);
		}
	}

}
